﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Fis.Win.Rules
{
    public class TaxRateViewProvider : ClientViewProvider
    {
        public override System.Collections.Hashtable InitializeViewModel(System.Collections.Hashtable args)
        {
            var model = args ?? new System.Collections.Hashtable();
            model["data"] = DataContext.DefaultModel.QueryTable(DataTableName);
            return model;
        }

        public override bool ExecuteUpdate(System.Collections.Hashtable viewModel)
        {
            var param = Fis.Win.Utils.AppSession.CreateServiceParamter(new System.Collections.Hashtable());
            param["action"] = "taxRate";
            param["data"] = Agile.Engine.Utils.ZipUtils.ZipDataTable(viewModel["data"] as System.Data.DataTable);

            var exec = InvokeService(param);
            View.Message = ServiceProcess.Message;
            if (exec)
            {
                var data = Agile.Engine.Utils.ZipUtils.UnZipDataTable(ServiceProcess.Result["data"].ToString());
                DataContext.DefaultModel.Delete(DataTableName, "1=1");
                DataContext.DefaultModel.UpdateTable(data, DataTableName, "1=1");
            }
            return exec;
        }
    }
}
